package o2o.dao.PO.company.postman;

import lombok.Data;
import lombok.experimental.Accessors;
import o2o.cache.company.postman.PostCompanyMemory;
import o2o.cache.postman.CityPostmanMemory;
import o2o.cache.user.UserInfoMemory;
import o2o.postman.model.CityPostman;
import o2o.dao.PO.user.UserInfo;
import o2o.dao.VO.company.postman.PostmanSignCompanyInfoVO;
import o2o.web.actions.company.postman.PostCompanyMan;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.BeanUtils;

import java.io.Serializable;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 *
 * @User: @Created by yangtk
 * @Date: @Date 2019/8/1 15:59
 * @Classname: PostmanSignCompanyInfo
 * @To change this template use File | Settings | File Templates.
 */
@Data
@Accessors(chain = true)
public class PostmanSignCompanyInfo implements Serializable {

    public final static Integer POSTMAN_COMPANY_SIGN_STATUS_APPLYING = 1;       // 签约状态-审核中
    public final static Integer POSTMAN_COMPANY_SIGN_STATUS_AGREE = 9;          // 签约状态-已通过
    public final static Integer POSTMAN_COMPANY_SIGN_STATUS_DISAGREE = -1;       // 签约状态-被拒绝

    private Long id;
    private String sysAppKey;
    private Long companyId;
    private String username;
    private Long postTypeId;
    private Integer postType;
    private Long applyTime;
    private Long dealTime;
    private int status = 1; //1 申请中 9 已同意 -1已拒绝
    private String refuseReason;
    private String note;
    private Double money;
    private int delFlag = 0;
    private String createUser;
    private Long createTime;
    private String updateUser;
    private Long updateTime;


    public PostmanSignCompanyInfoVO convert2VO() {
        PostmanSignCompanyInfoVO infoVO = new PostmanSignCompanyInfoVO();
        BeanUtils.copyProperties(this, infoVO);
        if (StringUtils.isNotEmpty(this.getUsername())) {
            UserInfo userInfo = UserInfoMemory.getInstance().getUserInfo(this.getUsername());
            if (userInfo != null) {
                infoVO.setName(userInfo.getName()).setTelPhone(userInfo.getTelPhone());
            }
            CityPostman postman = CityPostmanMemory.getInstance().getPostman(userInfo.getUsername());
            if (postman != null) {
                infoVO.setIsLock(postman.getIsLock()).setIsWork(postman.getIsWork()).setPostmanUsername(postman.getUsername());
            }
        }
        // postTypeName
        List<PostTypeInfo> typeInfos = PostCompanyMan.listOfPostmanType(null);
        if (typeInfos != null) {
            for (PostTypeInfo info1 : typeInfos) {
                if (infoVO.getPostType() != null && info1 != null && info1.getType() != null && info1.getType() == infoVO.getPostType()) {
                    infoVO.setPostTypeName(info1.getName()).setPostType(info1.getType());
                    break;
                }
            }
        }
        // 公司
        PostCompanyInfo postCompanyInfo = PostCompanyMemory.getInstance().getById(this.getCompanyId());
        if (postCompanyInfo != null) {
            infoVO.setPostCompanyName(postCompanyInfo.getCompanyName()).setPostCompanyAddress(postCompanyInfo.getAddress());
        }
        return infoVO;
    }

}
